import React from 'react';
import { Alert, Skeleton } from 'antd';
import { useRequest, defaultFormatResult } from '@/hooks';
import { queryEmployeeCourseList } from '@/pages/Organization/EmployeeManage/services';
import OnboardAndLeaveSection from '@/pages/Organization/EmployeeManage/components/EmployeeInfoSections/OnboardAndLeaveSection';

/**
 * 员工详情 - 微微历程
 */
const CourseTabContent = ({ employeeCode, title }) => {
    // 入转调离记录数据
    const { data: courseData, loading: courseLoading, error: courseError } = useRequest(
        () => queryEmployeeCourseList({ employeeCode }),
        {
            cacheKey: `employee-course-${employeeCode}`,
            refreshDeps: [employeeCode],
            ...defaultFormatResult
        }
    );

    // 错误处理
    if (courseError) {
        return <Alert type="error" message={courseError?.msg || '数据加载错误'} />;
    }

    // render
    return (
        <Skeleton loading={!courseData || courseLoading} active>
            {/* 入转调离记录 */}
            <OnboardAndLeaveSection formData={courseData} title={title} />
        </Skeleton>
    );
};

export default CourseTabContent;
